package cn.zz.comm.helper;

import cn.zz.comm.exception.classes.RecordEarlyUseException;
import cn.zz.comm.exception.classes.RecordNotFoundException;

import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author zhongq
 * @since 2024/5/22
 */
public class BizCommHelper {

	public static <T> void requireNull(T domain, Object... messages) {
		if (domain != null) {
			String msg = Stream.of(messages).filter(Objects::nonNull).map(Object::toString)
					.collect(Collectors.joining(" "));
			throw new RecordEarlyUseException(msg);
		}
	}

	public static <T> void requireNoNull(T domain, Object... messages) {
		if (domain == null) {
			String msg = Stream.of(messages).filter(Objects::nonNull).map(Object::toString)
					.collect(Collectors.joining(" "));
			throw new RecordNotFoundException(msg);
		}
	}
}